import java.util.HashMap;
import java.util.Map;

public class HashMapDemo01 {
    public static void main(String[] args) {
        //创建羊羊对象
        Sheep sheep1 = new Sheep("喜羊羊","公");
        Sheep sheep2 = new Sheep("美羊羊","母");
        //创建保存羊羊键值对的对象
        Map sheeps = new HashMap<>();
        sheeps.put("大聪明",sheep1);
        sheeps.put("大漂亮",sheep2);
        //羊的个数
        System.out.println(sheeps.size());
        //获取所有key的集合
        System.out.println(sheeps.keySet());
        //获取所有value的集合
        System.out.println(sheeps.values());
        //键集
        System.out.println(sheeps.entrySet());
        //判断大聪明是否在key集合中
        String key = "大聪明";
        if (sheeps.containsKey(key)) {
            Sheep sheep = (Sheep) sheeps.get(key);
            System.out.println("被人叫做" + key + "的羊羊是：" + sheep.getName() + ",它是一只" + sheep.getGender() + "羊");
        }
        //判断大漂亮是否在key集合中，如果在就删除它
        key = "大漂亮";
        if (sheeps.containsKey(key)) {
            Sheep abs = (Sheep) sheeps.remove(key);
            System.out.println("新星横空出世，" + key + "被碾压，在这个草原上已不复存在，只记得它的名字叫" + abs.getName() + "，是一只艳绝江湖的" + abs.getGender() + "羊");
        }


    }
}
